package tools

import com.google.gson.Gson
import exceptions.ErrorBotIdException
import java.io.FileReader

fun main() {
    println("Hello BotMgr")
    //println(BotMgr.getName(15L))
    println(BotMgr.getName(149674824601))
}


object BotMgr {
    class Bot (val botId: Long, val name: String, val admin: Long)
    class BotConfig (val bots: Array<Bot>)
    private val botMap = mutableMapOf<Long, Bot>()
    init {
        val gson = Gson()
        val jsonReader = FileReader("./config/config.json")
        val botConfig = gson.fromJson(jsonReader, BotConfig::class.java)
        for (bot in botConfig.bots) {
            botMap[bot.botId] = bot
        }
    }

    @JvmStatic
    fun getName(botId: Long): String {
        if (botId in botMap.keys) {
            return botMap[botId]?.name ?: ""
        }
        throw ErrorBotIdException()
    }
}